import React from 'react';
import { Form, Input, DatePicker } from 'antd';
import { SelectForm, SearchInput } from '@/components/UserForm';
import AdvancedSearch from '@/components/AdvancedSearch';
import { getApplyjob } from '@/services/components/userform';
import { getemployeebyrole } from '@/services/myRecruit/interview';
import TreeSelectPro from '@/components/TreeSelectPro/TreeSelectPro';
import useTreeSelectData from '@/hooks/useTreeSelectData';
import { withRouter } from 'umi';

const { RangePicker } = DatePicker;

const SearchForm = ({ form, onSearch, user, identity }) => {
    const { getFieldDecorator } = form;
    const [companyTreeData, companyTreeLoading] = useTreeSelectData('company');
    const handleSubmit = e => {
        form.validateFields(err => {
            if (!err) {
                // onSearch(values); values没有使用到
                onSearch(e);
            }
        });
    };
    return (
        <AdvancedSearch
            form={form}
            onSubmit={() => handleSubmit({ eType: 'submit' })}
            onReset={() => handleSubmit({ eType: 'reset' })}
        >
            <Form.Item label="姓名">
                {getFieldDecorator('candidateName', {})(<Input placeholder="请输入关键字搜索姓名" allowClear />)}
            </Form.Item>
            <Form.Item label="应聘职位">
                {getFieldDecorator(
                    'recruitCode',
                    {}
                )(
                    <SelectForm
                        params={{ companyId: user.companyId }}
                        requireParam={[]}
                        getData={params =>
                            getApplyjob(params).then(res => {
                                if (res && res.code === 10000 && res.data) {
                                    return res.data || [];
                                }
                                return [];
                            })
                        }
                        fieldsName={{
                            selectValue: 'recruitCode',
                            selectTitle: 'recruitName'
                        }}
                        // onChange={this.companyChange}
                        selectProps={{
                            placeholder: '请选择应聘职位',
                            allowClear: true,
                            dropdownMatchSelectWidth: false
                        }}
                    />
                )}
            </Form.Item>
            {/* <Form.Item label="公司">
                {getFieldDecorator(
                    'companyId',
                    {}
                )(
                    <TreeSelectForm
                        params={{}}
                        requireParam={[]}
                        getData={params =>
                            getCompanyTree(params).then(res => {
                                if (res && res.code === 10000 && res.data) {
                                    return res.data || [];
                                }
                                return [];
                            })
                        }
                        fieldsName={{
                            value: 'id',
                            title: 'companyName'
                        }}
                        Props={{
                            placeholder: '请选择所属公司',
                            showArrow: true,
                            allowClear: true
                        }}
                    />
                )}
            </Form.Item> */}
            <Form.Item label="公司">
                {form.getFieldDecorator('companyId', { initialValue: undefined })(
                    <TreeSelectPro
                        loading={companyTreeLoading}
                        showSearch
                        treeDefaultExpandAll
                        treeData={companyTreeData}
                        placeholder="请选择所属公司"
                        allowClear
                    />
                )}
            </Form.Item>
            <Form.Item label="面试时间：">{getFieldDecorator('insertDate', {})(<RangePicker />)}</Form.Item>
            {identity === 'apply' || identity === 'admin' ? (
                <Form.Item label="面试官">
                    {getFieldDecorator(
                        'interviewEmployeeId',
                        {}
                    )(
                        <SearchInput
                            params={{
                                companyId: user.companyId,
                                roleName: '面试官'
                            }}
                            requireParam={['companyId']}
                            getData={params =>
                                getemployeebyrole(params).then(res => {
                                    if (res && res.code === 10000) {
                                        return res.data || [];
                                    }
                                    return [];
                                })
                            }
                            fieldsName={{
                                value: 'id',
                                title: 'employeeName',
                                extraParams: 'employeeName'
                            }}
                            selectProps={{
                                placeholder: '请输入姓名',
                                mode: 'multiple',
                                maxTagCount: 3
                            }}
                        />
                    )}
                </Form.Item>
            ) : (
                ''
            )}
            {identity === 'ing' || identity === 'admin' ? (
                <Form.Item label="招聘负责人">
                    {getFieldDecorator(
                        'interviewLeaderId',
                        {}
                    )(
                        <SearchInput
                            params={{
                                companyId: user.companyId,
                                roleName: '招聘负责人'
                            }}
                            requireParam={['companyId']}
                            getData={params =>
                                getemployeebyrole(params).then(res => {
                                    if (res && res.code === 10000) {
                                        return res.data || [];
                                    }
                                    return [];
                                })
                            }
                            fieldsName={{
                                value: 'id',
                                title: 'employeeName',
                                extraParams: 'employeeName'
                            }}
                            selectProps={{
                                placeholder: '请输入姓名',
                                mode: 'multiple',
                                maxTagCount: 3
                            }}
                        />
                    )}
                </Form.Item>
            ) : (
                ''
            )}
        </AdvancedSearch>
    );
};
export default withRouter(SearchForm);
